package cn.wuqingna.legendgem.gui


import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import taboolib.library.configuration.ConfigurationSection
import taboolib.module.chat.colored


public enum class SlotType(var type: String) : SlotTypeInterface{
    ITEM("item") {

        override fun getItem(config: ConfigurationSection): ItemStack {
            return buildItem(config)
        }
    },
    USEITEM("useitem"){
        override fun getItem(config: ConfigurationSection): ItemStack {
            return  if (config.contains("type")) {
                buildItem(config)
            } else {
                ItemStack(Material.AIR)
            }
        }
    },
    GEM("gem") {
        override fun getItem(config: ConfigurationSection): ItemStack {
            return  if (config.contains("type")) {
                buildItem(config)
            } else {
                ItemStack(Material.AIR)
            }
        }

    },
    LUCK("luck") {
        override fun getItem(config: ConfigurationSection): ItemStack {
            return  if (config.contains("type")) {
                buildItem(config)
            } else {
                ItemStack(Material.AIR)
            }
        }

    },
    PROTECTIVE("protective") {
        override fun getItem(config: ConfigurationSection): ItemStack {
            return  if (config.contains("type")) {
                buildItem(config)
            } else {
                ItemStack(Material.AIR)
            }
        }

    };
    fun buildItem(config: ConfigurationSection): ItemStack{
        val item = ItemStack(Material.getMaterial(config.getString("type")), 1 , config.getInt("data").toShort())
        val meta = item.itemMeta
        meta.displayName = config.getString("display-name")!!.colored()
        meta.lore = config.getStringList("lore").colored()
        item.itemMeta = meta
        return item
    }
}